package com.black.service.service;


import com.alibaba.fastjson2.JSONObject;
import com.black.protocol.Response;
import com.black.service.dao.DataDao;
import com.black.service.entity.DataEntity;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@Service
public class DataServiceImpl implements DataService {

    @Resource
    private DataDao dataDao;

    @Override
    public Response<JSONObject> list(JSONObject param) {
        Integer page = param.getInteger("page");
        Integer size = param.getInteger("size");
        PageHelper.startPage(page, size);
        DataEntity entity = param.toJavaObject(DataEntity.class);
        List<DataEntity> list = dataDao.getList(entity);
        JSONObject result = new JSONObject();
        result.put("total", PageInfo.of(list).getTotal());
        result.put("list", list);
        return Response.success(result);
    }
}
